package app.fugema.shop.main.goods.adapter;

import android.view.View;

import com.base.common.utils.UIUtils;
import com.base.common.view.adapter.MyFlexboxLayoutManager;
import com.base.common.view.adapter.ada.BaseRVAdapter;
import com.base.common.view.adapter.connector.BaseItemMultiType;
import com.base.common.view.adapter.connector.BaseItemTypeInterface;
import com.base.common.view.adapter.connector.BaseViewHolder;
import com.base.common.view.widget.imageView.ImageLoaderUtils;

import app.fugema.shop.R;
import app.fugema.shop.databinding.ItemHeaderVshopInfoViewBinding;
import app.fugema.shop.main.goods.model.ShopHeadInfoBean;
import app.fugema.shop.main.goods.view.ShopInfoActivity;

public class ShopHeaderInfoItemMultiType  extends BaseItemMultiType<ShopHeadInfoBean, ItemHeaderVshopInfoViewBinding>
{
    @Override
    public int getLayoutId()
    {
        return R.layout.item_header_vshop_info_view;
    }

    @Override
    public int getItemViewType()
    {
        return BaseItemTypeInterface.TYPE_HEAD_ONE;
    }

    @Override
    public boolean isFullSpanType()
    {
        return true;
    }

    @Override
    public void onCreateViewHolder(ItemHeaderVshopInfoViewBinding binding, BaseViewHolder viewHolder)
    {
        super.onCreateViewHolder(binding, viewHolder);
        binding.rvRecyclerView.setLayoutManager(new MyFlexboxLayoutManager(binding.getRoot().getContext()));
        binding.rvRecyclerView.setAdapter(new SimpleCouponAdapter());
    }

    @Override
    public void onBindViewHolder(ItemHeaderVshopInfoViewBinding binding, int position, ShopHeadInfoBean bean)
    {
        super.onBindViewHolder(binding, position, bean);
        if( UIUtils.isNotEmpty( bean.getShopBean().getLogo() ) )
        {
            ImageLoaderUtils.loadImage( binding.ivShopLogo , bean.getShopBean().getLogo() );
        }
        binding.tvShopName.setText( bean.getShopBean().getName() );

        if( binding.rvRecyclerView.getAdapter() instanceof SimpleCouponAdapter )
        {
            SimpleCouponAdapter rvAdapter = (SimpleCouponAdapter) binding.rvRecyclerView.getAdapter();
            if( UIUtils.isNotEmpty( bean.getCoupon() ) && !bean.getCoupon().isEmpty() )
            {
                rvAdapter.setDataList( bean.getCoupon() );
                rvAdapter.setOnItemClickInterface((view, onclickType, itemType, position1, bean1) -> {
                    UIUtils.showToastSafes("打开优惠券");
                    return false;
                });
            }
        }
    }


    @Override
    public void onItemClick(View view, BaseRVAdapter adapter, int onclickType, int position, ShopHeadInfoBean bean)
    {
        super.onItemClick(view, adapter, onclickType, position, bean);
        int shopId = bean.getShopBean().getShopId();
        switch (view.getId())
        {
            case R.id.btn_shop_collect:
                UIUtils.showToastSafes("设置关注店铺");

                break;
            case R.id.tv_shop_name:
            case R.id.iv_shop_logo:
                ShopInfoActivity.start(view.getContext(),shopId);
                break;


        }
    }


}
